package example.lec05;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class User3 {
    @Bean(name="address")
    public Address address() {
        return new Address();
    }    
    @Bean(name="user")
    public User user() {
        return new User();
    }    
    //使用SpEL引用类的静态常量，或者静态方法。
    //调用其他类的静态常量实际就是调用了该属性对应的get方法，
    //所以设值静态常量的类还需要定义get方法，并且是public类型
    @Value("#{T(example.lec05.Address).address}")
    private String username;
    @Value("#{T(example.lec05.Address).getAddress()}")
    private String password;
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String toString() {
        return "user3 username:"+getUsername()+", password:"+getPassword();
    }
}
